package com.cyt.sys.interceptor;

import com.cyt.base.util.SpringApplicationContextUtil;
import com.cyt.sys.model.po.ParamConfig;
import com.cyt.sys.service.impl.SysParamConfigServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * lisence拦截器
 *
 * Created by dingxu on 2019/4/20.
 */
public class LisenceInterceptor extends HandlerInterceptorAdapter {

    private static Log log= LogFactory.getLog(LisenceInterceptor.class);

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        SysParamConfigServiceImpl paramConfigService=(SysParamConfigServiceImpl) SpringApplicationContextUtil.getBean("paramConfigService");
        ParamConfig paramConfig= paramConfigService.selectByKey("lisence");
        if(paramConfig==null){
            request.getRequestDispatcher("/login").forward(request,response);
            return  false;
        }
        return true;
    }

}
